import 'dart:math';

import 'package:faker/common/config.dart';
import 'package:faker/widgets/item_rsssource_list.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

class GridPage extends StatefulWidget {
  final String rssTag;

  GridPage({Key key, @required this.rssTag}) : super(key: key);

  @override
  GridPageState createState() => new GridPageState();
}

class GridPageState extends State<GridPage> {
  ScrollController _scrollController = new ScrollController();

  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil.getInstance()..init(context);
    return Container(
      color: Theme.of(context).backgroundColor,
      child: Scaffold(
        body: Padding(
          padding: const EdgeInsets.only(top: 24),
          child: StaggeredGridView.countBuilder(
            controller: _scrollController,
            itemCount: rssTag[widget.rssTag].length,
            primary: false,
            scrollDirection: Axis.vertical,
            crossAxisCount: 4,
            mainAxisSpacing: 4.0,
            crossAxisSpacing: 4.0,
            itemBuilder: (context, index) => TileCard(
              rss: rssTag[widget.rssTag][index],
              cardNo: Random().nextInt(20),
            ),
            staggeredTileBuilder: (index) => StaggeredTile.fit(2),
          ),
        ),
      ),
    );
  }

  @override
  void initState() {
    super.initState();
  }
}
